﻿@{
	 Dictionary<string ,string> msg=ViewBag.msg;
}
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="keywords" content="leanote,蚂蚁笔记,leanote.com">
	<meta name="description" content="leanote, 蚂蚁笔记, {{msg $ "moto"}}">
	<meta name="author" content="leanote,蚂蚁笔记">
	<title>@ViewBag.Title</title>

	<link href="/css/bootstrap.css" rel="stylesheet">
	<link href="/css/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">
	<link href="/css/index.css" rel="stylesheet">
	<style>
		html, body {
			height: 100%;
		}
	</style>
</head>
<body id="boxBody">
	<!-- 验证码 -->
	<script type="text/x-jsrender" id="tCaptcha">
		<div class="form-group">
			<label class="control-label">@msg["captcha"]</label>
			<input type="text" class="form-control" id="captcha" name="captcha">
			@*<a id="reloadCaptcha" title="@msg["reloadCaptcha"]" onclick="$('#captchaImage').attr('src', '/api/VerifyCode?random=' + ((new Date()).getTime()))"><img src="/captcha/get?random=@DateTime.Now.ToString("yyyyMMddHHmmssffff")" id="captchaImage" /></a>*@
			<a id="reloadCaptcha" title="@msg["reloadCaptcha"]" onclick="$('#captchaImage').attr('src', '@Url.Action("VerifyCode","API")?random=' + Math.round(new Date().getTime()/1000))"><img src="@Url.Action("VerifyCode","API")?random=@DateTime.Now.ToString("yyyyMMddHHmmssffff")" id="captchaImage" /></a>
		</div>
	</script>
	<section id="box" class="animated fadeInUp">
		<!--
		<div>
			<a class="back" href="javascript:history.go(-1);" tabindex="-1">←Back</a>
		</div>
		-->
		<div>
			<h1 id="logo"></h1>
			<div id="boxForm">
				<div id="boxHeader">网站初安装向导</div>
                <form>
                    <div class="alert alert-danger" id="loginMsg"></div>
                    @*<input id="from" type="hidden" value="{{.from}}" />*@
                    <input id="from" type="hidden" />
          
                    <div class="form-group">
                        <label class="control-label">请在这里粘贴配置文件</label>
						<textarea  id="config"  class="form-control" rows="20"   name="json">@ViewBag.config</textarea>
                    </div>
					<div class="form-group">
                        <label class="control-label">安装秘钥</label>
						<input type="text"  id="InstallKey"  class="form-control" rows="1"   name="InstallKey" value="cat /morenote/InstallKey.txt"/>
                    </div>
                    
                    <div id="captchaContainer">

                    </div>

                    <div class="clearfix">
                        <a href="/findPassword" class="pull-right m-t-xs"><small>需要帮助</small></a>
                        <button id="loginBtn" class="btn btn-success">初始化</button>
                    </div>


                    <div class="line line-dashed"></div>

                    
                </form>
			</div>
		</div>
	</section>

	

	<script src="/js/jquery-1.9.0.min.js"></script>
	<script src="/js/bootstrap.js"></script>

	<script>
$(function() {
	var needCaptcha = true;

	if(needCaptcha){
		$("#captchaContainer").html($("#tCaptcha").html());
	}

	$("#email").focus();
	if($("#email").val()) {
		$("#pwd").focus();
	}
	function showMsg(msg, id) {
		$("#loginMsg").html(msg).show();
		if(id) {
			$("#" + id).focus();
		}
	}
	function hideMsg() {
		$("#loginMsg").hide();
	}
	$("#loginBtn").click(function(e){
		e.preventDefault();
		var config = $("#config").val();
		var captcha = $("#captcha").val()
		if(!config) {
			showMsg("无效的配置文件", "email");
			return;
		}

		if(needCaptcha && !captcha) {
			showMsg("@msg["inputCaptcha"]", "captcha");
			return;
		}

		$("#loginBtn").html("@msg["logining"]...").addClass("disabled");
		// hideMsg();
		//安装完成后跳转
		$.post("/System/DoInstall", {config: config, captcha: $("#captcha").val()}, function(e) {
			$("#loginBtn").html("@msg["login"]").removeClass("disabled");
			if(e.Ok) {
				$("#loginBtn").html("初始化成功...");
				var from = "/";
				location.href = from;
			} else {
				if(e.Item && $.trim($("#captchaContainer").text()) == "") {
					$("#captchaContainer").html($("#tCaptcha").html());
					needCaptcha = true
				}
				showMsg(e.Msg);
			}
		});
	});
});
	</script>
</body>
</html>
